PWD := $(shell pwd)

# TOOLCHAIN=/home/wk/gpu/outsource/3A4000_module/mips-loongson-gcc4.9-linux-gnu/2019.08-05
# ROOTFS=/home/wk/gpu/outsource/3A4000_module/staging
# CROSS_COMPILE=mips-linux-gnu-
# CFLAGS			  += -mabi=64

TOOLCHAIN=/usr/bin
ROOTFS=/
CROSS_COMPILE=

LIB_DIR=${TOOLCHAIN}/lib
ROOTFS_USR=${ROOTFS}/usr

CC                := $(CROSS_COMPILE)gcc
CXX               := $(CROSS_COMPILE)g++
AR                := $(CROSS_COMPILE)ar
AS                := $(CROSS_COMPILE)as
LD                := $(CROSS_COMPILE)link

export PATH:=${TOOLCHAIN}/bin:${PATH}

demo_so_lib=demo_so.o
demo_implicit=demo_implicit.o
demo_explicit=demo_explicit.o

.DEFAULT_GOAL := all

demo_so:$(demo_so_lib)
	$(CC) $(CFLAGS) $^ -fPIC -shared -o libdemo.so

implicit:$(demo_implicit)
	$(CC) $(CFLAGS) $^ -o demo_implicit -L${PWD} -ldemo

explicit:$(demo_explicit)
	$(CC) $(CFLAGS) $^ -o demo_explicit -ldl

.PHONY : all
all:
	@make demo_so
	@make implicit
	@make explicit
	@./run.sh

.PHONY : clean
clean:
	rm *.o *.so demo_implicit demo_explicit
